﻿using System;
using System.Web.Security;
using DDDProject.Aspects;
using DDDProjectSample.Application.Controllers;

namespace DDDProjectSample.WebUI
{
    public partial class Logon : System.Web.UI.Page
    {
        [InjectComponent]
        private MembersController _membersController;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Logon_Click(object sender, EventArgs e)
        {
            // Call domain controller to know if the user is valid
            bool isValidUser = _membersController.ValidateMember(UserEmail.Text, UserPass.Text);

            if (isValidUser)
            {
                FormsAuthentication.RedirectFromLoginPage(
                    UserEmail.Text, 
                    Persist.Checked);
            }
            else
            {
                Master.ErrorMessage = "Invalid credentials. Please try again.";
            }
        }
    }
}
